/**
 *	@file	telseq_masaki.c
 *	@brief	マサキ　会話データ抽選＆再生
 *	@author	Miyuki Iwasawa
 *	@date	09.02.06
 */

#include "common.h"
#include "system/procsys.h"
#include "system/arc_util.h"
#include "system/arc_tool.h"
#include "system/bmp_list.h"
#include "system/bmp_menu.h"
#include "system/pm_str.h"
#include "system/msgdata.h"
#include "system/fontproc.h"
#include "system/snd_tool.h"
#include "system/buflen.h"
#include "system/pm_rtc.h"
#include "gflib/touchpanel.h"
#include "field/eventflag.h"
#include "field/evwkdef.h"
#include "fielddata/script/saveflag.h"
#include "itemtool/itemsym.h"
#include "msgdata/msg.naix"
#include "msgdata/msg_pg_tel.h"

#include "../pm_tel.h"
#include "tel/pmtel_def.h"
#include "tel/pmtel_datman.h"
#include "tel/pmtel_dat_def.h"
#include "../pmtel_seq.h"
#include "telseq_play.h"

#include "msgdata/msg_tel_p_masaki.h"

/**
 *	@brief	電話　マサキの会話抽選
 */
u16 PMTelPlayL_Masaki(PMTEL_DATA_MAN* wk,PMTEL_TALK_WORK* twk)
{
	//ノーマル着信
	if(twk->is_receive){
		twk->seq_code = TEL_SEQ_SIMPLE;
		return TEL_TK_MASAKI_BOX_FULL;
	}

	//同一マップにいるか？
	if(twk->pbk->map_id == wk->zone_id)	{
		twk->seq_code = TEL_SEQ_SIMPLE;
		return TEL_TK_MASAKI_NE;
	}
	//ノーマル発信
	twk->seq_code = TEL_SEQ_MASAKI_CALL;
	return 0;
}

/**
 *	@brief	マサキの送話シーケンス
 */
int PMTelSeq_TypeMasakiCall(PMTEL_DATA_MAN* wk)
{
	PMTEL_TALK_WORK *twk = &wk->twk;

	switch(twk->seq){
	case 0:
		//タグ展開処理
		PMTel_TagSpreadCommon(wk);
		break;
	case 1:
		//挨拶
		if(!PMTelSubSeq_GreetingMsgPlay(wk)) return FALSE;
		//相手の確認メッセージ再生
		PMTel_MsgPrintGmmSex(wk,wk->m_person,m_masaki_c01_m,m_masaki_c01_f);
		break;
	case 2:
		if(!PMTel_MsgPrintWait(wk)) return FALSE;

		//本文メッセージ再生開始
		{
			BOX_DATA* box_sv = SaveData_GetBoxData(wk->save);
			u32 num;

			//カレントボックス名展開
			BOXDAT_GetBoxName( box_sv,
				BOXDAT_GetCureentTrayNumber( box_sv ), wk->str_tmp );

			WORDSET_RegisterWord( wk->wset,WORDSET_TEL_LOCAL_BUF+0,
				wk->str_tmp, PM_NEUTRAL, TRUE, PM_LANG);

			//ボックスの空き
			num = BOXDAT_GetEmptySpaceTotal(box_sv);
			WORDSET_RegisterNumber( wk->wset, WORDSET_TEL_LOCAL_BUF+1,
				num, 3,	NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );

			IWASAWA_PRINT("BoxEmptySpace = %d\n",num);
			if(num == 0){
				PMTel_MsgPrintGmm(wk,wk->m_person,m_masaki_c02_full);
			}else{
				PMTel_MsgPrintGmm(wk,wk->m_person,m_masaki_c02_01+gf_rand()%3);
			}
		}
		break;
	case 3:
		//メッセージ再生待ち
		if(!PMTel_MsgPrintWait(wk)) return FALSE;
		//またでんわして
		PMTel_MsgPrintGmm(wk,wk->m_person,m_masaki_c03);
		break;
	case 4:
		if(!PMTel_MsgPrintWait(wk)) return FALSE;
		MSGMAN_Delete(wk->m_person);
		return TRUE;
	}
	++twk->seq;
	return FALSE;
}
